/**
 * Copyright (C) 2009 Noel Ang
 *
 * This file is part of Samsara.
 *
 * Samsara is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Samsara is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Samsara.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.lunarshades.samsara.ui.actions;

import com.lunarshades.samsara.Raider;

/**
 * A KarmaStatusEvent reports on the state of a karma entry.
 *
 * @author Noel Ang, sparta.variable@gmail.com
 */
public class KarmaStatusEvent<T extends Raider> extends KarmaChangeEvent<T> {

/**
 * Create a KarmaStatusEvent.
 *
 * @param subject The subject of the change.
 *
 * @throws NullPointerException if subject is null.
 */
public KarmaStatusEvent(T subject) {
    super(subject, 0);
}

protected String initMessage() {
    // STATUS [Person] Karma [44] karma.
    StringBuffer buffer = new StringBuffer();
    buffer.append("STATUS ");
    buffer.append("[");
    String id = subject().id();
    buffer.append(id);
    for (String name : subject().names()) {
        if (!name.equals(id)) {
            buffer.append('/').append(name);
        }
    }
    buffer.append("]");
    buffer.append(" Karma [").append(subject().karma().toString()).append("]");
    return buffer.toString();
}

/**
 * @return A representative message.
 */
public Object message() {
    if (mMessage == null) {
        mMessage = initMessage();
    }
    return mMessage;
}

private volatile String mMessage;
}
